package com.lmaos.basetools.proxy;

import java.util.ArrayList;
import java.util.List;


public class EnableProxyIntercepts<T> {
	List<EnableProxyIntercept<T>> enableProxyIntercepts = new ArrayList<EnableProxyIntercept<T>>();
	EnableProxyIntercept<T> defaultEnableProxyIntercept = null;
	public EnableProxyIntercepts() {
	
	}
	public EnableProxyIntercepts(
			EnableProxyIntercept<T> defaultEnableProxyIntercept) {
		super();
		this.defaultEnableProxyIntercept = defaultEnableProxyIntercept;
	}
	public boolean enableClassname(String classname){
		if(defaultEnableProxyIntercept!=null&&!defaultEnableProxyIntercept.enableClassname(classname)){
			return false;
		}
		
		for (EnableProxyIntercept<T> enableProxyIntercept : enableProxyIntercepts) {
			if(!enableProxyIntercept.enableClassname(classname)){
				return false;
			}
		}
		return true;
	}
	public boolean enableMethod(T method){
		if(defaultEnableProxyIntercept!=null&&!defaultEnableProxyIntercept.enableMethod(method)){
			return false;
		}
		for (EnableProxyIntercept<T> enableProxyIntercept : enableProxyIntercepts) {
			if(!enableProxyIntercept.enableMethod(method)){
				return false;
			}
		}
		return true;
	}
	public EnableProxyIntercepts<T> addEnableProxyIntercept(EnableProxyIntercept<T> enableProxyIntercept){
		enableProxyIntercepts.add(enableProxyIntercept);
		return this;
	}
	public  EnableProxyIntercepts<T> setDefaultEnableProxyIntercept(
			EnableProxyIntercept<T> defaultEnableProxyIntercept) {
		this.defaultEnableProxyIntercept = defaultEnableProxyIntercept;
		return this;
	}
}
